#include "StdAfx.h"
#include "Condition.h"
#include "Operation.h"
#include "Operand.h"
namespace _MODULE_
{
	namespace _GAME_
	{
		Condition::Condition(void)
		{
			m_ptrOperation = NULL;
			m_ptrOperand1 = NULL;//primary
			m_ptrOperand2 = NULL;//optional

			m_bResult=false;
		}

		Condition::~Condition(void)
		{
		}

		bool Condition::Check()
		{

			assert(m_ptrOperation&&"Condition::Check m_ptrOperation is NULL!!");
			assert(m_ptrOperand1&&"Condition::Check m_ptrOperand1 is NULL!!");

			bool result=false;

			//skip this condition is check in the past
			if(m_bResult)
				return true;

			//check condition
			m_ptrOperand1->Begin();

			while(m_ptrOperand1->GetVariable())
			{
				result = m_ptrOperation->Execute(m_ptrOperand1->GetVariable(),(m_ptrOperand2)?m_ptrOperand2->GetVariable():NULL);

				m_ptrOperand1->Next();

				if(result==false)
					break;
			}
			

			m_bResult=result;
			return result;
		}
	}
}